package net.lab1024.sa.admin.module.flowable.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import net.lab1024.sa.admin.module.business.goods.domain.form.GoodsQueryForm;
import net.lab1024.sa.admin.module.business.goods.domain.vo.GoodsVO;
import net.lab1024.sa.admin.module.flowable.annotation.EnterpriseAndApplicationCodeProperty;
import net.lab1024.sa.admin.module.flowable.domain.FlowableCategory;
import net.lab1024.sa.admin.module.flowable.domain.form.FlowableCategoryForm;
import net.lab1024.sa.admin.module.flowable.page.TableDataInfo;
import net.lab1024.sa.admin.module.flowable.service.IFlowableCategoryService;
import net.lab1024.sa.base.common.domain.PageResult;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 流程分类Controller
 *
 * @author ruoyi
 * @date 2023-11-27
 */
@RestController
@RequestMapping("/flowable/category")
public class FlowableCategoryController extends BaseController
{
    @Resource
    private IFlowableCategoryService flowableCategoryService;

    /**
     * 查询流程分类列表
     */
    @SaCheckPermission("flow:flow_classify:list")
    @GetMapping("/list")
    public ResponseDTO<TableDataInfo> list(FlowableCategory flowableCategory)
    {
        startPage();
        List<FlowableCategory> list = flowableCategoryService.selectFlowableCategoryList(flowableCategory);
        return ResponseDTO.ok(getDataTable(list));
    }

    @PostMapping("/query")
    @SaCheckPermission("flow:flow_classify:list")
    public ResponseDTO<PageResult<FlowableCategory>> query(@RequestBody @Valid FlowableCategoryForm queryForm) {
        return flowableCategoryService.query(queryForm);
    }

    /**
     * 导出流程分类列表
     */
/*    @SaCheckPermission("flow:flow_classify:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlowableCategory flowableCategory)
    {
        List<FlowableCategory> list = flowableCategoryService.selectFlowableCategoryList(flowableCategory);
        ExcelUtil<FlowableCategory> util = new ExcelUtil<FlowableCategory>(FlowableCategory.class);
        util.exportExcel(response, list, "流程分类数据");
    }*/

    /**
     * 获取流程分类详细信息
     */
    @SaCheckPermission("flow:flow_classify:query")
    @GetMapping(value = "/{id}")
    public ResponseDTO<FlowableCategory> getInfo(@PathVariable("id") Long id)
    {
        return ResponseDTO.ok(flowableCategoryService.selectFlowableCategoryById(id));
    }

    /**
     * 新增流程分类
     */
    @SaCheckPermission("flow:flow_classify:add")
    @PostMapping
    public ResponseDTO<Integer> add(@RequestBody FlowableCategory flowableCategory)
    {
        return ResponseDTO.ok(flowableCategoryService.insertFlowableCategory(flowableCategory));
    }

    /**
     * 修改流程分类
     */
    @SaCheckPermission("flow:flow_classify:update")
    @PutMapping
    public ResponseDTO<Integer> edit(@RequestBody FlowableCategory flowableCategory)
    {
        return ResponseDTO.ok(flowableCategoryService.updateFlowableCategory(flowableCategory));
    }

    /**
     * 删除流程分类
     */
    @SaCheckPermission("flow:flow_classify:delete")
	@DeleteMapping("/{ids}")
    public ResponseDTO<Integer> remove(@PathVariable Long[] ids)
    {
        return ResponseDTO.ok(flowableCategoryService.deleteFlowableCategoryByIds(ids));
    }
}
